package AbstractFactoryModel;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;

public class XMLUtil {
    public static Object GetBean(){

        try {
            DocumentBuilderFactory documentBuilderFactory=DocumentBuilderFactory.newInstance();
            DocumentBuilder documentBuilder=documentBuilderFactory.newDocumentBuilder();
            Document document=documentBuilder.parse(new File("src/main/java/AbstractFactoryModel/config.xml"));

            NodeList nodeList=document.getElementsByTagName("className");
            Node classNode=nodeList.item(0).getFirstChild();
            String className=classNode.getNodeValue();
            Class clazz=Class.forName(className);
            Object obj=clazz.newInstance();
            return obj;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
